package com.k8s.base.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;

/**
 * A Dict.
 */
@Entity
@Table(name = "sys_dict")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Dict implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotNull
    @Size(max = 64)
    @Column(name = "kind", length = 64, nullable = false)
    private String kind;

    @Column(name = "seq", nullable = false)
    private Long seq;

    @NotNull
    @Size(max = 256)
    @Column(name = "value", length = 256, nullable = false)
    private String value;

    @NotNull
    @Size(max = 128)
    @Column(name = "text", length = 128, nullable = false)
    private String text;

    @NotNull
    @Column(name = "is_system", nullable = false)
    private Boolean isSystem;

    @NotNull
    @Column(name = "is_read_only", nullable = false)
    private Boolean isReadOnly;

    @Size(max = 256)
    @Column(name = "remarks", length = 256)
    private String remarks;

    @Size(max = 1024)
    @Column(name = "data", length = 1024)
    private String data;

    @Column(name = "service_name")
    private String serviceName;

    @Column(name = "is_multi")
    private Boolean isMulti;

    @ManyToOne
    private Dict parent;

    @OneToMany(mappedBy = "parent")
    @JsonIgnore
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    private Set<Dict> children = new HashSet<>();

    @OneToMany(mappedBy = "dict",cascade = CascadeType.REMOVE)
    @JsonIgnore
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    private Set<DictOwner> owners = new HashSet<>();


    public Long getId() {
        return id;
    }
    public Dict id(Long id) {
        this.id = id;
        return this;
    }
    public void setId(Long id) {
        this.id = id;
    }

    public String getKind() {
        return kind;
    }

    public Dict kind(String kind) {
        this.kind = StringUtils.upperCase(kind, Locale.ENGLISH);
        return this;
    }

    public void setKind(String kind) {
        this.kind = StringUtils.upperCase(kind, Locale.ENGLISH);
    }

    public Long getSeq() {
        return seq;
    }

    public Dict seq(Long seq) {
        this.seq = seq;
        return this;
    }

    public void setSeq(Long seq) {
        this.seq = seq;
    }

    public String getValue() {
        return value;
    }

    public Dict value(String value) {
        this.value = value;
        return this;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getText() {
        return text;
    }

    public Dict text(String text) {
        this.text = text;
        return this;
    }

    public void setText(String text) {
        this.text = text;
    }

    public Boolean isIsSystem() {
        return isSystem;
    }

    public Dict isSystem(Boolean isSystem) {
        this.isSystem = isSystem;
        return this;
    }

    public void setIsSystem(Boolean isSystem) {
        this.isSystem = isSystem;
    }

    public Boolean isIsReadOnly() {
        return isReadOnly;
    }

    public Dict isReadOnly(Boolean isReadOnly) {
        this.isReadOnly = isReadOnly;
        return this;
    }

    public void setIsReadOnly(Boolean isReadOnly) {
        this.isReadOnly = isReadOnly;
    }

    public String getRemarks() {
        return remarks;
    }
    public Dict remarks(String remarks) {
        this.remarks = remarks;
        return this;
    }
    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public String getData() {
        return data;
    }
    public Dict data(String data) {
        this.data = data;
        return this;
    }
    public void setData(String data) {
        this.data = data;
    }

    public Dict getParent() {
        return parent;
    }

    public Dict parent(Dict dict) {
        this.parent = dict;
        return this;
    }

    public void setParent(Dict dict) {
        this.parent = dict;
    }

    public Set<Dict> getChildren() {
        return children;
    }

    public Dict children(Set<Dict> dicts) {
        this.children = dicts;
        return this;
    }

    public Dict addChildren(Dict dict) {
        children.add(dict);
        dict.setParent(this);
        return this;
    }

    public Dict removeChildren(Dict dict) {
        children.remove(dict);
        dict.setParent(null);
        return this;
    }

    public void setChildren(Set<Dict> dicts) {
        this.children = dicts;
    }


    public Set<DictOwner> getOwners() {
        return owners;
    }

    public Dict owners(Set<DictOwner> owners) {
        this.owners = owners;
        return this;
    }

    public Dict addOwner(DictOwner owner) {
        owners.add(owner);
        owner.setDict(this);
        return this;
    }

    public Dict removeOwner(DictOwner owner) {
        owners.remove(owner);
        owner.setDict(null);
        return this;
    }

    public void setOwners(Set<DictOwner> owners) {
        this.owners = owners;
    }

    public String getServiceName() {
        return serviceName;
    }

    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }

    public Dict serviceName(String serviceName) {
        this.serviceName = serviceName;
        return this;
    }

    public Boolean getIsMulti() {
        return isMulti;
    }

    public void setIsMulti(Boolean isMulti) {
        this.isMulti = isMulti;
    }

    public Dict isMulti(Boolean isMulti) {
        this.isMulti = isMulti;
        return this;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Dict dict = (Dict) o;
        if (dict.id == null || id == null) {
            return false;
        }
        return Objects.equals(id, dict.id);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(id);
    }

    @Override
    public String toString() {
        return "Dict{" +
            "id=" + id +
            ", kind='" + kind + "'" +
            ", seq='" + seq + "'" +
            ", value='" + value + "'" +
            ", text='" + text + "'" +
            ", isSystem='" + isSystem + "'" +
            ", isReadOnly='" + isReadOnly + "'" +
            ", remarks='" + remarks + "'" +
            '}';
    }
}
